"""
极简壁纸
js逆向
https://bz.zzzmh.cn/index
"""
import requests
import execjs
import base64
import time

url = "https://api.zzzmh.cn/bz/v3/getData"
res = requests.post(url, json={
    "size": 24,
    "current": 6,
    "sort": 0,
    "category": 0,
    "resolution": 0,
    "color": 0,
    "categoryId": 0,
    "ratio": 0
})
info = res.json().get("result")
# info = "ak+9VCsq4dEdB+UdUfGo8kh5JDEbMHGTCmF/AyXJQ0IgGEanUAivRFLreN3rh1PP2wTUOByEP6sZuFGJAezyg9rgZStPA6xJ+j9L3h9lfJ/+zIfKG1j6Eh/bWp9BcjXF3RMhCk3P2kFG5fHTLs+yMdL+FT/KuJmhFwD/OgVZj+gePyUknDag/rgmZBSsUXkUT+1501V6hZgJ0vuBLeHPQ4WPcc+hZWk5dO4FmTeRqx+e+iq1IXGoFBDC7DoLk/wDqTT8BwHRgZR+ibYi3qQH4yLIKCFj7UDw9WxFzatw98cEpoLET1Zw5JxgiCrYeRcLMiU+TghsmJ86erelcafLPb+TFX/xbD57UU7ybbPtH4WqHq9MKlmFUOh2OH1qt+64POe7OpsIi8Nsb9fMyhajmwizu3RHfC44AMBeVk2WtvYFx5gWSklErG8s11HJSLSJ4pUIamJKQyKVWXmrYwalKsFPvIL3QJ1LYbINGYZIE1GzkmLBHFGbB8MXCeesQpEx9k/b1yAiYx/OTTNW3TZFXAGsfEiF2B/LArXb8eEBJWVwp6AYL7z/6ITHhaIeCXWBtpdk06A1pEMT6ugurvYkVnm5/bE8MvejrIerM+pASVxMpTDS6RJKLDZB9dtuqy4sTzzrsUWLoIdySk1ZlXPIfb9rmiwiI0RTTQxd74YoNDEkI9whrQWws2tAXbJB/qR99agcqsaYe6qMmH0tW5h2NKRn7LTd2gwPzqKCEHBq1UbGFjlvoqfjEtbiqc8BRBmmgurh2yugiJgamOoiY0CQjZUh+SRjdRnfi3IvOnK7n7bUL6WRFc4mqN9Vud8ofDQkXJa95WSB+bxGhBlFNmbk8+OcnYnW62BNaGm8d6paUE4lmu8JiT3zm59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qgSea1P8s7tjF3i8RUYVYRSvmsoMP9zVYReF/QCO6nHqhzESwEfelq7vN4aEK7sgOff+OY9GGue8WexeWI5WQhTqA/lzfSJFjVFfV/ylLmNs5meOkrN1nqRUfyP7eezr/kOP3OJcMBgVxWklirnQUEqqBHE0fAIo17Z7yuf9na0vJYhg6VLzRQAJoBormCVhAJ7k4CrUNtU6k2G/xofL5slSTt7hasGil03Cv5OYDclGq0gBcUwFvAajQbUK"
info = base64.b64decode(info).decode("Latin1")
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
    "Referer": "https://bz.zzzmh.cn/"
}
with open("./js/parse_jijianbizhi.js", "r") as f:
    content = f.read()
    js_code = execjs.compile(content)
    result = js_code.call("parse", info)
    for image in result["list"]:
        time.sleep(1)
        thumb_image_url = f'https://api.zzzmh.cn/bz/v3/getUrl/{image["i"]}{image["t"] * 10}'
        thumb_image_res = requests.get(thumb_image_url, headers=headers)
        thumb_image_name = thumb_image_res.url.split("/")[5]
        with open(f"../datas/jijianbizhi/thumb/thumb_{thumb_image_name}", "wb") as f_img:
            f_img.write(thumb_image_res.content)

        time.sleep(1)
        preview_image_url = f'https://api.zzzmh.cn/bz/v3/getUrl/{image["i"]}{image["t"] * 10 + 1}'
        preview_image_res = requests.get(preview_image_url, headers=headers)
        preview_image_name = preview_image_res.url.split("/")[5]
        with open(f"../datas/jijianbizhi/preview/preview_{preview_image_name}", "wb") as f_img:
            f_img.write(preview_image_res.content)

        time.sleep(1)
        super_image_url = f'https://api.zzzmh.cn/bz/v3/getUrl/{image["i"]}{image["t"] * 10 + 9}'
        super_image_res = requests.get(super_image_url, headers=headers)
        super_image_name = super_image_res.url.split("/")[5].split("?")[0]
        with open(f"../datas/jijianbizhi/super/super_{preview_image_name}", "wb") as f_img:
            f_img.write(super_image_res.content)
        break
